import org.vaillant.todo.Status;
import org.vaillant.todo.StatusHistory;
import org.vaillant.todo.Task;
import org.vaillant.todo.User;

class BootStrap {

    def init = { servletContext ->
		
		Status openStatus = new Status(name:'open').save()
		Status finishStatus = new Status(name:'finish').save()
		
		User user1 = new User(userId:'joe').save()
		
		
		def now = new Date()
		def fewDay = now.minus(2)
		def lastWeek = fewDay.minus(7)
		def fewWeek = lastWeek.minus(15)
		def lastMonth = fewWeek.minus(15)
		def lastYear = now.minus(400)
		
		Task t1 = new Task(description:'First task').save()
		t1.dateCreated = fewDay
		
		StatusHistory st1 = new StatusHistory()
		t1.addToStatus(st1)
		openStatus.addToStatusHistory(st1)
		st1.dateCreated = fewDay
		
		Task t2 = new Task(description:'Second task').save()
		t2.dateCreated = lastWeek
		StatusHistory st3 = new StatusHistory()
		t2.addToStatus(st3)
		openStatus.addToStatusHistory(st3)
		st3.dateCreated = lastWeek
		
		Task t3 = new Task(description:'Third task').save()
		t3.dateCreated = now
		StatusHistory st4 = new StatusHistory()
		t3.addToStatus(st4)
		openStatus.addToStatusHistory(st4)
		st4.dateCreated = now
		
		user1.addToTasks(t1)
		user1.addToTasks(t2)
		user1.addToTasks(t3)
		
		StatusHistory st2 = new StatusHistory(dateCreated:now)
		t1.addToStatus(st2)
		st2.dateCreated = now
		finishStatus.addToStatusHistory(st2)
		
		new User(userId:'jack').save()
		new User(userId:'john').save()
		new User(userId:'monica').save()
		new User(userId:'bill').save()
		
    }
    def destroy = {
    }
}
